<%layout("/common/_layout.html"){ %>
<script type="text/javascript">

function changeStatus(url,id,targetStatus) {
    
    $.ajax({
        url : url,
        data : {"id":id,"target_status":targetStatus},
        dataType : "json",
        async : true,
        success : function(data) {
            //parent.swal({title: "配置成功!", text: data.message, type: "success",timer: 2000,   showConfirmButton: false});
            parent.layer.msg("配置: " + data.message);
        }
        
    });
    
}
 
$(function(){
    var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
    $mycheckbox.each(function(){
        var myid = $(this).attr("id");
        $("#"+myid).on({
            'switchChange.bootstrapSwitch': function(event, state) {
              var id =$(this).attr("id") ;
              console.log("switch:"+id+":"+state);
              changeStatus("${base}/sku/changeOptStatus",id,state?1:0);
            }
        });
    });

  });
  
 
</script>



  <%#ajax userTable:{%>
  <div class="am-cf am-padding">
    <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">SKU管理</strong> / <small>当前Sku（${sku.name!}）的可用选项</small></div>
  </div>
  
  <div class="am-g">
    <div class="am-u-sm-12">
        <form class="am-form" id="list-form" action="${base}/sku/listOpt/${sku.id!}" method="post">
            <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
            <div class="am-g">
                        <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin-left:10px;">
                        <div class="am-btn-toolbar">
                         <button type="button" class="am-btn am-btn-warning am-btn-xs" onclick="window.location.href='${base}/sku/list'; return false;">返回上一级</button>
                         </div>
                        </div>
                 
                 
                    <div class="am-u-sm-12 am-u-md-3 am-input-group am-input-group-sm">
                        <input type="text" class="am-form-field" id="name" value="${name!}" placeholder="按选项名称搜索"/>
                        <span class="am-input-group-btn">
                            <button id="submit-btn" class="am-btn am-btn-default" type="button">搜索</button>
                        </span>
                    </div>
                </div>
            </div>
        </form>
    </div>
 <!--
    <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
       <div class="am-btn-toolbar" style="padding-left:.5rem;">
         <div class="am-btn-group am-btn-group-xs">
           
           <%if(so.hasPermission("SKUOPT_ADD")) {%>
            <div class="am-btn-group am-btn-group-xs am-form-file"><button type="button" id="bt_add" class="am-btn am-btn-default"  onclick="location.href='${base}/sku/addOpt?skuId=${sku.id!}'">新增</button></div>
           <%}%>
           
           <%if(so.hasPermission("SKUOPT_DELETE")) {%>
            <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/sku/deleteOpt?skuId=${sku.id!}')"><span class="am-icon-trash-o"></span> 删除</button>
           <%}%>
          
         </div>
       </div>
    </div>
 -->
   <div class="am-g">
     <div class="am-u-sm-12">
        <div class="am-scrollable-horizontal">
         <table class="am-table am-table-striped am-table-hover table-main">
             <thead>
                  <tr class="am-text-nowrap">
                     <!--<th class="table-check">
                     <input type="checkbox"  id="allCheck"/></th>-->
                     <th class="table-title">名称</th>
                     <!--<th class="table-title">代码</th>-->
                     <th class="table-title">编辑者</th>
                     <th class="table-title">编辑时间</th>
                     <!--<th class="table-title">是否可用</th>
                     <th class="table-title">操作</th>-->
                  </tr>
             </thead>
          <tbody>
             <%for(item in pager.list!){%>
                <tr>
                 <!--<td><input type="checkbox" name="ids" value="${item.id}"></td>-->
                 <td>${item.name}</td>
                 <!--<td>${item.code}</td>-->
                 <td>${item.operated_by}</td>
                 <td>${item.operated_time}</td>
                 <!--
                 <td>
                    <div class="switch-button"> 
                        <input id="${item.id}"  type="checkbox" data-size='xs' data-am-switch  data-off-text="禁用" data-on-text="可用"  
                        <%if(item.enabled==1){%>
                                checked
                        <%}else{%><%}%>
                        />
                    </div>
                 </td>  
                 -->      
                 <!--
                 <td>
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <%if(so.hasPermission("SKUOPT_EDIT")) {%>
                                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/sku/editOpt?id=${item.id}&skuId=${sku.id!}'">
                                    <span class="am-icon-pencil-square-o"></span>编辑</button>
                            <%}%>
                        </div>
                    </div>
                 </td>
                 -->
                </tr>
             <%}%> 
          </tbody>
       </table>
       </div>
       
       
       <div class="am-cf">
         <!-- 分页 -->
         <%if (pager.list.~size > 0){%>
             <div class="am-fr">
                 <% include("/admin/common_pager.tpl"){}%>
             </div>
         <%}else{%>
             <div class="am-kai">
               <h3>没有找到任何记录!</h3>
             </div>
         <%}%>
      </div>
      

  
      </div>
  </div>
  

   
 <div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">
        <i class="am-icon-refresh am-icon-spin"></i>
        <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
      </div>
      <div class="am-modal-bd">
        正在处理，请稍等...
      </div>
    </div>
  </div>
  
  <script type="text/javascript">
    $(function(){
      var keywordsObj = {};
      $("#submit-btn").on("click",function(){
        if($("#name").val())
          keywordsObj.name = $("#name").val();
             
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);

        $("#keywords").val(keywords);
        $("#list-form").submit();
      });
    });
 
  </script>
<%}%>
<%}%> 